<?
include_once "../conn.php";
?>

<script src="prototype.js"></script>
<SCRIPT LANGUAGE="JavaScript">
<!--
function findSub(){
new Ajax.Request('findstate.php', {
	method: 'get',
	parameters:{
						 
						 id: $F('country')
						},
	onLoading: function() { $('sub').update('Loading...') },
	onSuccess: function(transport){
						 if(transport.responseText){
						 	$('sub').update(transport.responseText);
						}
					}
				});
}
//-->
</SCRIPT>


<?


if(isset($s1))
{
	if(!empty($job_category))
	{
		$pc = implode("|", $job_category);
	}

     $query = "insert into job_seeker_info set 
										uname = \"$uname\",
										upass = \"$upass\",
										title = \"$title\",
										fname = \"$fname\",
										lname = \"$lname\",
										bmonth = \"$month\",
										bday = \"$day\",
										byear = \"$year\",
										age = \"$age\",
										maritalstatus = \"$maritalstatus\",
										sex = '$sex',
										income = \"$income\",
										country = \"$country\",
										zip = \"$zip\",
										address = \"$address\",
										street = '$street',
										city = '$city',
										state = '$state',
										fax = '$fax',
										phone = \"$phone\",
										phone2 = \"$phone2\",
										job_seeker_email = \"$job_seeker_email\",
										job_category = \"$pc\",
										careerlevel = \"$careerlevel\",
										target_company = \"$target_company\",
										nationality = '$nationality' ";

			$result = mysql_query($query);

			if(mysql_error())
			{
				$error = "<br><span class=TNA>Duplicate username: <span class=BlackLink>$uname</span></span>";
				unset($uname);
			}
			else
			{
				//get the user info
				$q3 = "select * from job_seeker_info where uname = '$uname' ";
				$r3 = mysql_query($q3) or die(mysql_error());
				$a3 = mysql_fetch_array($r3);

				//send an email
				$to = $a3[job_seeker_email];
				$subject = "Your registration at $_SERVER[HTTP_HOST]";
				$message_body = "Hello $a3[fname],\nhere is login information for $_SERVER[HTTP_HOST]\n\nUsername: $a3[uname]\nPassword: $a3[upass]\n\nKeep this information in a secure place.\n\nThanks for your registration.\nWe believe you will find a job at \n http://$_SERVER[HTTP_HOST]";

				$headers = "MIME-Version: 1.0\n"; 
				$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
				$headers .= "Content-Transfer-Encoding: 8bit\n"; 
				$headers .= "From: $_SERVER[HTTP_HOST] <$aset[ContactEmail]>\n"; 
				$headers .= "X-Priority: 1\n"; 
				$headers .= "X-MSMail-Priority: High\n"; 
				$headers .= "X-Mailer: PHP/" . phpversion()."\n"; 

				mail($to, $subject, $message_body, $headers);

				$_SESSION[uname] = $uname;

				echo "<script>top.location = 'thanks.php'</script>"; 

				exit();
			}
}

include_once "../main.php";

?>


<br>

<script>
function CheckReg1() {

	var d = document.f1;

	if(d.title.value=="")
	{
		alert('Select your title, please!');
		d.title.focus();
		return false;
	}

	if(d.fname.value=="")
	{
		alert('Enter your first name, please!');
		d.fname.focus();
		return false;
	}

	if(d.lname.value=="")
	{
		alert('Enter your last name, please!');
		d.lname.focus();
		return false;
	}

	if(d.nationality.value=="")
	{
		alert('Enter your nationality, please!');
		d.nationality.focus();
		return false;
	}

	if(d.month.value=="" || d.day.value=="" || d.year.value=="")
	{
		alert('Enter your birth date, please!');

		if(d.month.value=="")
		{
			d.month.focus();
		}
		else if(d.day.value=="")
		{
			d.day.focus();
		}
		else if(d.year.value=="")
		{
			d.year.focus();
		}

		return false;
	}

	if(!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(d.job_seeker_email.value))
	{
		alert("Invalid E-mail Address! Please re-enter.");
		d.job_seeker_email.value="";
		d.job_seeker_email.focus();
		return false;
	}

	if(d.careerlevel.value=="")
	{
		alert('Select your career level, please!');
		d.careerlevel.focus();
		return false;
	}

	if(d.uname.value=="")
	{
		alert('Enter your login name, please!');
		d.uname.focus();
		return false;
	}			

	if(d.upass.value=="")
	{
		alert('Enter your password, please!');
		d.upass.focus();
		return false;
	}

	if(d.cpass.value=="")
	{
		alert('Confirm your password, please!');
		d.cpass.focus();
		return false;
	}

	if(d.upass.value != "" && d.cpass.value != "" && d.upass.value != d.cpass.value)
	{
		alert('Enter and confirm your password again!');
		d.upass.value="";
		d.cpass.value="";
		d.upass.focus();
		return false;
	}

}
</script>

<form action="jobseeker_registration.php" method=post OnSubmit="return CheckReg1();" name=f1>
<table width=600 border=0 align=center cellpadding="3" cellspacing=0 class=BlackText>
<caption align=center class=HeaderClass>Jobseeker registration form<?=$error?>
<br />
<br />
</caption>

<tr>
	<td colspan=2 class="BlackLink row1"><strong>Personal details</strong></td>
</tr>
<tr>
	<td>
		<br>	</td>
</tr>
<tr> 
	<td align=left>Title <font color=red>*</font></td>
	<td>
		<select name="title">
			<option value="Mr." <? if($title == "Mr.") { echo "selected"; } ?>>Mr.</option>
            <option value="Mrs." <? if($title == "Mrs.") { echo "selected"; } ?>>Mrs.</option>
            <option value="Miss." <? if($title == "Miss.") { echo "selected"; } ?>>Miss.</option>
            <option value="Ms." <? if($title == "Ms.") { echo "selected"; } ?>>Ms.</option>
            <option value="Dr." <? if($title == "Dr.") { echo "selected"; } ?>>Dr.</option>
        </select>	</td>
</tr>

<tr>
	<td align=left>First name:<font color=red>*</font></td>
	<td><input type=text name=fname size=23 value="<?=$fname?>"></td>
</tr>


<tr>
	<td align=left>Last name:<font color=red>*</font></td>
	<td><input type=text name=lname size=23 value="<?=$lname?>"></td>
</tr>

<tr>
	<td align=left>Nationality:<font color=red>*</font></td>
	<td><input type=text name=nationality value="<?=$nationality?>"></td>
</tr>

<tr>
	<td align=left>Age: <font color=red>*</font>	</td>
	<td><input type=text name=age value="<?=$age?>"></td>
</tr>

<tr>
	<td align=left>Date of birth: <font color=red>*</font>	</td>
	<td><?=select_date("$_POST[month]/$_POST[day]/$_POST[year]");?></td>
</tr>


<tr>
	<td align=left>Marital Status:</td>

	<td>
	<SELECT NAME="maritalstatus">
              <option value="Single" <? if($maritalstatus == "Single") { echo "selected"; } ?>>Single</option>
              <option value="Married" <? if($maritalstatus == "Married") { echo "selected"; } ?>>Married</option>
              <option value="Divorced" <? if($maritalstatus == "Divorced") { echo "selected"; } ?>>Divorced</option>
              <option value="Engaged" <? if($maritalstatus == "Engaged") { echo "selected"; } ?>>Engaged</option>
              <option value="Separated" <? if($maritalstatus == "Separated") { echo "selected"; } ?>>Separated</option>
              <option value="Widowed" <? if($maritalstatus == "Widowed") { echo "selected"; } ?>>Widowed</option>
	</SELECT>	</td>
</tr>

<tr>
	<td align=left>Sex:</td>
	<td>
		<select name=sex>
			<option value=""></option>
			<option value="male">Male</option>
			<option value="female">Female</option>
		</select>	</td>
</tr>
<tr>
	<td>
		<br>	</td>
</tr>
<tr>
	<td colspan=2 class="BlackLink row1"><strong>Home address</strong></td>
</tr>
<tr>
	<td>
		<br>	</td>
</tr>
<tr>
	<td align=left>Address:</td>
	<td><input type=text name=address value="<?=$address?>"></td>	
</tr>

<tr>
	<td align=left>Street:</td>
	<td><input type=text name=street value="<?=$street?>"></td>	
</tr>

<tr>
	<td align=left>Town/City:</td>
	<td><input type=text name=city value="<?=$city?>"></td>	
</tr>

<tr>
	<td align=left>State/Province:</td>
	<td>
		<div id="sub">
			<select name=state>
				<option value=" ">Select</option>
<?php
foreach ($state as $key => $value){
?>
		<option value="<?=$value?>"><?=$value?></option>
<?
}
?>	
			</select>
		</div></td>	
</tr>

<tr>
	<td align=left>Country:</td>
	<td><?=select_country($country, "country");?></td>	
</tr>

<tr>
	<td align=left>Zip/Postal code:</td>
	<td><input type=text name=zip size=7 value="<?=$zip?>"></td>
</tr>

<tr>
	<td align=left>Telephone:</td>
	<td><input type=text name=phone value="<?=$phone?>"></td>
</tr>

<tr>
	<td align=left>Mobile:</td>
	<td><input type=text name=phone2 value="<?=$phone2?>"></td>
</tr>

<tr>
	<td align=left>Fax:</td>
	<td><input type=text name=fax value="<?=$fax?>"></td>
</tr>

<tr>
	<td align=left>Email:<font color=red>*</font></td>
	<td><input type=text name=job_seeker_email value="<?=$job_seeker_email?>"></td>
</tr>
<tr>
	<td>
		<br>	</td>
</tr>
<tr>
	<td colspan=2 class="BlackLink row1"><strong>Job requirements</strong></td>
</tr>
<tr>
	<td>
		<br>	</td>
</tr>

<tr>
	<td align=left valign=top>Job requirements:</td>
	<td>
		<table border=0 width=450>
			<tr>
				
<?php
$c = 0;
foreach ($categories AS $key => $value){		
?>		
	<td><input type='checkbox' name='job_category[]' value='<?=$value?>'><?=$value?></td>
<?php
$c++;
		if($c==2){
			echo "</tr><tr>";
			$c = 0;
		}	
}
?>
		</tr>
	</table>	</td>
</tr>

<tr>
	<td align=left>Your career level:<font color=red>*</font></td>

	<td><?=career_level($_POST[careerlevel], "");?></td>
</tr>

<tr>
	<td align=left>Target company:</td>

	<td><?=target_company($target_company);?></td>
</tr>

<tr> 
	<td  align=left colspan=1>Min. Annual Salary Requirement<font color=red>*</font>:</td>
	<td><select name="income">
              <option value="Under 40,000" <? if($income == "Under 40,000") { echo "selected"; } ?>>Under 40,000</option>
              <option value="40,000-60,000" <? if($income == "40,000-60,000" || empty($income)) { echo "selected"; } ?>>40,000-60,000</option>
              <option value="60,000-80,000" <? if($income == "60,000-80,000") { echo "selected"; } ?>>60,000-80,000</option>
              <option value="80,000-100,000" <? if($income == "80,000-100,000") { echo "selected"; } ?>>80,000-100,000</option>
              <option value="100,000-150,000" <? if($income == "100,000-150,000") { echo "selected"; } ?>>100,000-150,000</option>
              <option value="150,000-200,000" <? if($income == "150,000-200,000") { echo "selected"; } ?>>150,000-200,000</option>
              <option value="200,000 &and over" <? if($income == "200,000 &and over") { echo "selected"; } ?>>200,000 &and over</option>
            </select>	</td>
</tr>
<tr>
	<td>
		<br>	</td>
</tr>
<tr>
	<td colspan=2 class="BlackLink row1"><strong>Login details</strong></td>
</tr>
<tr>
	<td>
		<br>	</td>
</tr>

<tr>
	<td align=left>Username:<font color=red>*</font></td>
	<td><input type=text name=uname size=23 maxlength=10 value="<?=$uname?>"> max. 10 symbols</td>
</tr>

<tr>
	<td align=left>Password:<font color=red>*</font></td>
	<td><input type=password name=upass size=23 maxlength=10 value="<?=$upass?>"> max. 10 symbols</td>
</tr>

<tr>
	<td align=left>Confirm password:<font color=red>*</font></td>
	<td><input type=password name=cpass size=23 maxlength=10 value="<?=$cpass?>"></td>
</tr>

<tr>

	<td align=left>&nbsp;</td>

	<td align=right>
	  <input class="s2" type="submit" name="s1" value="Register me" align="left" />&nbsp;
	  <input class=s2 type=reset name=reset value="Reset" align=right>	</td>
</tr>
</table>
</form>

<? include_once('../footer.php'); ?>